package com.turnengine.client.global.user.command;

import com.javabi.common.locale.LanguageCountry;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Signup User.
 */
public class SignupUser implements ISignupUser {

	/** The command id. */
	public static final short COMMAND_ID = 501;

	/** The name. */
	private String name;
	/** The password. */
	private String password;
	/** The email. */
	private String email;
	/** The address. */
	private int address;
	/** The language. */
	private LanguageCountry language;

	/**
	 * Creates a new Signup User.
	 */
	public SignupUser() {
	}

	/**
	 * Creates a new Signup User.
	 * @param name the name
	 * @param password the password
	 * @param email the email
	 * @param address the address
	 * @param language the language
	 */
	public SignupUser(String name, String password, String email, int address, LanguageCountry language) {
		setName(name);
		setPassword(password);
		setEmail(email);
		setAddress(address);
		setLanguage(language);
	}

	/**
	 * Creates a new Signup User.
	 * @param iSignupUser the i signup user
	 */
	public SignupUser(ISignupUser iSignupUser) {
		setName(iSignupUser.getName());
		setPassword(iSignupUser.getPassword());
		setEmail(iSignupUser.getEmail());
		setAddress(iSignupUser.getAddress());
		setLanguage(iSignupUser.getLanguage());
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the password.
	 * @return the password.
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Returns the email.
	 * @return the email.
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Returns the address.
	 * @return the address.
	 */
	public int getAddress() {
		return address;
	}

	/**
	 * Returns the language.
	 * @return the language.
	 */
	public LanguageCountry getLanguage() {
		return language;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		if (name == null) {
			throw new NullPointerException("name");
		}
		this.name = name;
	}

	/**
	 * Sets the password.
	 * @param password the password to set.
	 */
	public void setPassword(String password) {
		if (password == null) {
			throw new NullPointerException("password");
		}
		this.password = password;
	}

	/**
	 * Sets the email.
	 * @param email the email to set.
	 */
	public void setEmail(String email) {
		if (email == null) {
			throw new NullPointerException("email");
		}
		this.email = email;
	}

	/**
	 * Sets the address.
	 * @param address the address to set.
	 */
	public void setAddress(int address) {
		this.address = address;
	}

	/**
	 * Sets the language.
	 * @param language the language to set.
	 */
	public void setLanguage(LanguageCountry language) {
		if (language == null) {
			throw new NullPointerException("language");
		}
		this.language = language;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(233, 37);
		hash.append(name);
		hash.append(password);
		hash.append(email);
		hash.append(address);
		hash.append(language);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof SignupUser) {
			SignupUser compare = (SignupUser) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.name, compare.name);
			equals.append(this.password, compare.password);
			equals.append(this.email, compare.email);
			equals.append(this.address, compare.address);
			equals.append(this.language, compare.language);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ISignupUser compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.name, compare.getName());
		builder.append(this.password, compare.getPassword());
		builder.append(this.email, compare.getEmail());
		builder.append(this.address, compare.getAddress());
		builder.append(this.language, compare.getLanguage());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		if (name != null) {
			string.append("name", name);
		}
		if (password != null) {
			string.append("password", password);
		}
		if (email != null) {
			string.append("email", email);
		}
		string.append("address", address);
		if (language != null) {
			string.append("language", language);
		}
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
